# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from decimal import Decimal
from typing import List, Union
from fastapi import Query
from pydantic import BaseModel, Field


class BillSearchIn(BaseModel):
    """ 账单搜索参数 """
    page_no: int = Query(gt=0, default=1, description="当前页码")
    page_size: int = Query(ge=1, default=15, description="每页条数")
    start_time: Union[str, int, None] = Query(default=None, description="开始时间")
    end_time: Union[str, int, None] = Query(default=None, description="结束时间")


class SubscribePackageIn(BaseModel):
    """ 套餐搜索参数 """
    calendar: Union[str, None] = Query(default="", description="日期类型")

    class Config:
        json_schema_extra = {
            "example": {
                "calendar": "month"
            }
        }


class SubscribePlaceIn(BaseModel):
    """ 订单下单参数 """
    package_id: int = Field(gt=0, description="订阅套餐ID")

    @classmethod
    def messages(cls):
        return {
            "package_id.ge": "请正确选择套餐",
        }

    class Config:
        json_schema_extra = {
            "example": {
                "package_id": 1
            }
        }


"""--------------- Separator ---------------"""


class SubscribeSpecificVo(BaseModel):
    """ 订阅描述Vo """
    name: str = Field(description="权益名称")
    description: str = Field(description="权益描述")
    is_support: int = Field(description="权益状态")

    class Config:
        json_schema_extra = {
            "example": {
                "name": "AI积分",
                "description": "1000点",
                "is_support": 1
            }
        }


class SubscribePackageVo(BaseModel):
    """ 订阅套餐Vo """
    id: int = Field(description="套餐ID")
    pricing_id: int = Field(description="定价ID")
    name: str = Field(description="套餐名称")
    tags: str = Field(description="套餐标签")
    description: str = Field(description="套餐描述")
    sell_price: Decimal = Field(description="销售价格")
    line_price: Decimal = Field(description="划线价格")
    my_version: int = Field(description="我的版本: [0=否, 1=是]")
    is_purchase: int = Field(description="允许购买: [0=否, 1=是]")
    is_builtin: int = Field(description="系统内置: [0=否, 1=是]")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    specifics: List[SubscribeSpecificVo] = Field(default=[], description="权益描述")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "pricing_id": 1,
                "name": "0.01",
                "tags": "tags",
                "description": "this is description",
                "sell_price": 10.88,
                "line_price": 168.80,
                "my_version": 0,
                "is_purchase": 1,
                "is_builtin": 1,
                "is_disable": 0,
                "specifics": [
                    {
                        "name": "AI积分",
                        "description": "1000点",
                        "is_support": 1
                    }
                ]
            }
        }


class SubscribeListVo(BaseModel):
    """ 订阅列表Vo """
    class Options(BaseModel):
        type: str = Field(description="选项类型")
        label: str = Field(description="选项名称")

    scene: str = Field(description="当前场景")
    option: List[Options] = Field(description="场景选项")
    lists: List[SubscribePackageVo] = Field(default=[], description="套餐列表")

    class Config:
        json_schema_extra = {
            "example": {
                "scene": "month",
                "option": [
                    {
                        "type": "day",
                        "label": "按日"
                    },
                    {
                        "type": "month",
                        "label": "按月"
                    }
                ],
                "lists": [
                    {
                        "id": 1,
                        "name": "免费版",
                        "description": "先人一步体验 AI 生产力",
                        "sell_price": 12.26,
                        "line_price": 66.86,
                        "specifics": [
                            {
                                "name": "对话积分",
                                "description": "1000",
                                "is_support": 1
                            }
                        ]
                    }
                ]
            }
        }


class SubscribePlaceVo(BaseModel):
    """ 订阅下单结果Vo """
    order_id: int = Field(description="ID")
    paid_amount: Decimal = Field(description="应付金额")

    class Config:
        json_schema_extra = {
            "example": {
                "order_id": 1,
                "paid_amount": 16.88
            }
        }


class SubscribeBillingVo(BaseModel):
    """ 订阅账单记录Vo """
    order_sn: str = Field(description="订单编号")
    pay_way: str = Field(description="支付方式")
    pay_status: str = Field(description="支付状态")
    package_name: str = Field(description="套餐名称")
    order_amount: Decimal = Field(max_digits=10, decimal_places=2, default=0, description="订单金额")
    paid_amount: Decimal = Field(max_digits=10, decimal_places=2, default=0, description="支付金额")
    package_end_time: str = Field(description="套餐到期时间")
    pay_time: str = Field(description="支付时间")
    create_time: str = Field(description="创建时间")

    class Config:
        json_schema_extra = {
            "example": {
                "order_sn": "20250124155758636245",
                "pay_way": "微信支付",
                "pay_status": "已支付",
                "package_name": "标准版",
                "order_amount": 49.0,
                "paid_amount": 49.0,
                "package_end_time": "",
                "pay_time": "",
                "create_time": "2025-01-24 15:57:58"
            }
        }


class SubscribeRecordVo(BaseModel):
    """ 订阅开通记录Vo """
    name: str = Field(description="套餐名称")
    is_effect: bool = Field(description="当前生效")
    is_perpetual: bool = Field(description="是否永久")
    effect_time: str = Field(description="生效时间")
    expire_time: str = Field(description="到期时间")

    class Config:
        json_schema_extra = {
            "example": {
                "name": "套餐订阅(免费版)",
                "is_effect": True,
                "is_perpetual": False,
                "effect_time": "2025-03-18 16:05",
                "expire_time": "2025-04-18 16:05"
            }
        }

